<?php

#INCLUDE
include "../site_specific/project.php";
include "../includes/constants.php";
include "../site_specific/external_constants.php";
include "../includes/phpmailer/class.phpmailer.php";
include "../includes/phpmailer/class.smtp.php";
include "../includes/utilities.php";
include "../includes/pages.php";
include "../includes/database.php";
include "../includes/users.php";
include "../includes/date.php";
include "../includes/text.php";
include "../includes/files.php";

# Establish database connection
establishDatabaseConnection();

$selected_page_id=$_GET["id"];

$sql="SELECT * FROM apollo_pages WHERE p_id=\"".$selected_page_id."\"";

$result=getRecord($sql);

$page_content=$result[0]["p_content"];

$main_output = parseFlashLinks(parseFlashXML($page_content));

#Change the original hyper link style to the one with css
$main_output = ChangeHyperLinkStyle($main_output);
						  
$multiple_choice_searching_item_begin="<multiple-choice>";
						  
$multiple_choice_searching_item_end="</multiple-choice>";
						  
if(strpos($main_output,$multiple_choice_searching_item_begin)&& strpos($main_output,$multiple_choice_searching_item_begin)){
							  
	$main_output=ReplaceMulitpleChoice($main_output,false);
}
				
$seaching_content = getRecord("SELECT gl_letter,gl_term,gl_descripto FROM apollo_glossary order by gl_letter");
						  
$question_searching_item="<a href=\"www.uq.edu.au\">solution</a>";

$main_output=ReplaceFontFamily($main_output);
						  
$main_output=marked_keyword_replace($main_output,$seaching_content);						  
						  
$main_output=glossary_replace($main_output,$seaching_content);
						  
#remove the none link Indentifier
$main_output=RemoveHyperlink($main_output,"***","###");
						  
#replace the reference indetifier.
$main_output=Replace_reference($main_output);
						  					  						  
if(strpos($main_output,$question_searching_item)){
	  $main_output=removetable($main_output);
	  $exersice_array=explode($question_searching_item,$main_output);
	  $main_output=$exersice_array[0];
	  $main_output.="<a href=\"javascript:expandAnswer('".$PAGE -> getData("p_id")."',1,'div_quesiton_answer_0','answer_expand_img_0');\"><img id=\"answer_expand_img_0\" border=\"0\" src=\"../assets/images/tree/folder_closed_1.png\"></a><div id=\"div_quesiton_answer_0\"></div>";
}

$main_output=str_replace($question_searching_item,"",$main_output);

echo $main_output;
?>